import { ElMessage, ElMessageBox } from 'element-plus'
const commonUtil = {
    Methods: {
        ShowMessage: (type, msg) => {
            if (type == 'Oops') {
                ElMessage.error(msg)
            } else {
                ElMessage({
                    message: msg,
                    type: type,
                    duration: 5000
                })
            }
        },
        confirm: (msg, func: Function) => {
            ElMessageBox.confirm(
                msg,
                '友情提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    draggable: true,
                }
            )
                .then(() => {
                    func();
                })
                .catch(() => {
                   
                })
        },
        formatDate: (value) => {
            if (value == undefined || value == null) {
                return '';
            }
            let date = new Date(value);
            return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
        },
        generateGUID: () => {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
                let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }
    }
};

export default commonUtil;